package com.roy.ai.service;

import com.alibaba.fastjson2.JSON;
import dev.langchain4j.model.openai.OpenAiChatModel;
import dev.langchain4j.service.AiServices;

import java.util.ArrayList;
import java.util.List;

/**
 * @author 山顶洞人郑某
 * @className AiService.java AI 服务
 * @date 2025 04 01
 */
public class AiService {
  /*  public static void main(String[] args) {
        System.out.println("nihao");
        Assistant assistant = AiServices.builder(Assistant.class)
                .chatLanguageModel(OpenAiChatModel.builder().modelName("gpt-4o-mini")
                        .apiKey("demo").build()).systemMessageProvider(o -> "你是一个人工智能的RAG助手").build();

        System.out.println(assistant.chat("你好"));
    }*/
 //调用大模型返回自定义的POJO对象
    public static void main(String[] args) {

      List<Assistant.User> userMessages = new ArrayList<>();
      for (int i = 0;i<100;i++) {
        Assistant.User user = new Assistant.User("姓名"+i,i%2 == 0 ?"男":"女" );
        userMessages.add(user);
      }
      Assistant assistant = AiServices.builder(Assistant.class)
              .chatLanguageModel(OpenAiChatModel.builder()
                      .modelName("gpt-4o-mini")
                      .apiKey("demo")
                      .strictJsonSchema(true)
                      .build()).systemMessageProvider(o ->
                      "你是一个人工智能的对给定内容按照sex进行分类并返回JSON集合的助手").build();
      //将userMessages转换为JSON格式
    //  System.out.println(JSON.toJSONString(userMessages));
      String category = assistant.category(JSON.toJSONString(userMessages));
      //将category Json格式字符串转换为集合
      System.out.println(category);
    }
}
